import 'dart:io';
import 'dart:math';

import 'package:flu_framework/common/utility/config.dart';
import 'package:flu_framework/common/utility/native_channel_util.dart';
import 'package:flu_framework/common/widgets/dialog_utils.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bugly/flutter_bugly.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:umeng_common_sdk/umeng_common_sdk.dart';

import 'common/utility/navigator_provider.dart';
import 'get_pages.dart';
import 'http/http_utils.dart';

void main() async{

  WidgetsFlutterBinding.ensureInitialized();
  await SpUtil.getInstance();
  // UserInfoManager().getUserInfo();
  // _initEyeProtection();
  _initCacheData();
  FlutterBugly.postCatchedException(() {
    // 如果需要 ensureInitialized，请在这里运行。
    // WidgetsFlutterBinding.ensureInitialized();
    runApp(GetMaterialApp(
      navigatorKey: NavigatorProvider.navigatorKey,
      title: '学大在线',
      initialRoute: PageName.PAGE_SPLASH,
      getPages: pages,
    ));


  });

  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
  HttpUtils.initDio();
  Config.initLocation();

  // ZxCourseCatalogsUtil.putDefaultZxCourseCatalogs();
}

_initEyeProtection()
{
  bool eye = SpUtil.getBool('sp_save_eye_mode') ?? false;
  NativeChannelUtil.invokeNativeMethod(
      NativeChannelUtil.EYE_PROTECTION_MODE,
      param:{'eyeMode':eye}
  );
}

_initCacheData(){
  double? cache = SpUtil.getDouble("cache_size",defValue: 0);
  double cacheSum = cache!+Random().nextDouble();
  SpUtil.putDouble("cache_size",cacheSum);
}
